

package com.google.code.tcx2nike;

/**
 * Represents workout data in Nike+ XML format.
 * Current implementation mimics a very simpel data format
 * from www.nikeplusedit.com.
 */
public class NikeWorkoutData {
	// properties that will be set in nike xml file
	def startTime
	def runDuration
    def distance
	def weight
	
	def writer
	def builder
	def nike
	
	NikeWorkoutData(startTime, runDuration, distance, weight) {
		
		this.startTime = startTime
		this.runDuration = runDuration
		this.distance = distance
		this.weight = weight
		
	}
	
	def init() {
		writer = new StringWriter()
		builder = new groovy.xml.MarkupBuilder(writer)	
	}
	
	def buildXml () {

		//TODO: use actual data here instead of strings

		nike = builder.sportsData() {
			version(2)
			runsummary() {
				workoutName('name')
				time('2009-09-25T18:00:00-18:00')
				duration('1800000')
				durationString('30:00')
				distance(unit:"km", '4')
				distanceString('4 km')
				pace('7:30 min/km')
				calories('280')
				battery('')
				stepCounts() {
					walkBegin('0')
					walkEnd('0')
					runBegin('0')
					runEnd('0')
				}
				template() {
					templateID('8D495DCE')
					templateName('templateName')
				}
				goal(type:'', value:'', unit:'', "")
				userinfo() {
					empedID('XXXXXXXXXXX')
					device('device')
					calibration('')
				}
				startTime('2009-09-25T18:00:00-18:00')
				extendedDataList() {
					extendedData(dataType:"distance", intervalType:"time", intervalUnit:"s", intervalValue:"10")
				}
				
				
			}
		}
	}
	
	def String toString() {
		writer.toString()
	}
	
}